package com.example.RuanJianKeShe.Service.teacher;

import com.alibaba.fastjson.JSON;
import com.example.RuanJianKeShe.Bean.Teacher;
import com.example.RuanJianKeShe.Dao.impl.TeacherDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.HashMap;

@WebServlet("/getTeacherInfoByTno")
public class getTeacherInfoByTno extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setContentType("application/json;charset=utf-8");
        HttpSession session = req.getSession();
        Object myTno = session.getAttribute("myTno");
        TeacherDaoImpl teacherDao = new TeacherDaoImpl();
        Teacher teacher = teacherDao.getTeacherById(Integer.parseInt(myTno.toString()));
        HashMap<String,Object> map = new HashMap<>();
        map.put("info",teacher);
        String jsonString = JSON.toJSONString(map);
        resp.getWriter().write(jsonString);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
